Using Sentinels in Insert Sort

نویسنده

  • Harold W. Thimbleby
چکیده

Although insert sort takes quadratic time in the worst case it has a very efficient inner loop. Its bestcase computing time is linear, which occurs when the data are already in sorted order. It is the method of choice for data stored in linked lists or small arrays. Algorithm 1 is typical, and is written in extended Pascal. Implementing the conditional 'cand' operation (to guard against the error of subscripting the array a when j–1=0) is problematic in Pascal. Though other languages (Ada, C, Algol, etc.) can overcome this problem of expression, the algorithm nevertheless performs two tests within the loop when only one is sufficient, as we shall see below. There are other optimizations, covered by Knuth,' which we shall not discuss here, for instance: (a) various minor transformations, such as initializing j to j–1, unwinding the inner loop and noticing that a[i]: =v is unnecessary when the inner loop is not executed

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

An improved insert sort algorithm

Many algorithms involve a search, and they typically require two types of test: one test checks for the element being searched for, and another test is required to check the search remains within the bounds of the data structure being searched. Both of these tests can be combined into one by using a so-called sentinel. In particular, sentinels can be used in insert sort algorithms to make them ...

متن کامل

Insert Sort on Scmpds

The goal of this article is to examine the effectiveness of “forloop” and “while-loop” statements on SCMPDS by insert sort. In this article, first of all, we present an approach to compute the execution result of “for-loop” program by “loop-invariant”, based on Hoare’s axioms for program verification. Secondly, we extend the fundamental properties of the finite sequence and complex instructions...

متن کامل

Insert Sort on SCMPDS 1

The goal of this article is to examine the effectiveness of “for-loop” and “while-loop” statements on SCMPDS by insert sort. In this article, first of all, we present an approach to compute the execution result of “for-loop” program by “loop-invariant”, based on Hoare’s axioms for program verification. Secondly, we extend the fundamental properties of the finite sequence and complex instruction...

متن کامل

I/O-Efficient Well-Separated Pair Decomposition and its Applications

We present an external memory algorithm to compute a well-separated pair decomposition (WSPD) of a given point set P in d in O sort N I/Os using O N B blocks of external memory, where N is the number of points in P, and sort N denotes the I/O complexity of sorting N items. (Throughout this paper we assume that the dimension d is fixed). We also show how to dynamically maintain the WSPD in O log...

متن کامل

Insert Sort on SCM FSA 1

This article describes the insert sorting algorithm using macro instructions such as if-Macro (conditional branch macro instructions), for-loop macro instructions and While-Macro instructions etc. From the viewpoint of initialization, we generalize the halting and computing problem of the While-Macro. Generally speaking, it is difficult to judge whether the While-Macro is halting or not by way ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:
  • Softw., Pract. Exper.

دوره 19  شماره 

صفحات  -

تاریخ انتشار 1989